The ORDEREDHASH function creates a new ordered hash. An ordered hash is a compound data type that contains key-value pairs of different data types, including any mixture of scalars, arrays, structures, pointers, object references, dictionaries, lists, hashes, and other ordered hashes. Unlike HASH, the keys in an ordered hash are kept in the same order in which they are inserted.
Ordered hashes have the following properties:
Note: Since the ORDEREDHASH is so similar to HASH, most of the documentation can be found under HASH. Here we provide some examples of the differences between the two data types.
keys = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
values = LIST('one', 2.0, 3, 4l, PTR_NEW(5), {n:6}, COMPLEX(7,0))
hash = ORDEREDHASH(keys, values)
PRINT, hash
IDL prints:
A: one
B: 2.00000
C: 3
D: 4
E: <PtrHeapVar79>
F: { 6}
G: ( 7.00000, 0.000000)
keys = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
values = LIST('one', 2.0, 3, 4l, PTR_NEW(5), {n:6}, COMPLEX(7,0))
hash = HASH(keys, values)
PRINT, hash
IDL prints:
A: one
F: { 6}
C: 3
D: 4
G: ( 7.00000, 0.000000)
B: 2.00000
E: <PtrHeapVar31>
Notice that the regular hash returns the elements in an arbitrary order while the ordered hash preserves the original element order.
struct = {FIELD1: 4.0, FIELD2: {SUBFIELD1: "hello", SUBFIELD2: 3.14}}
hash = ORDEREDHASH(struct, /EXTRACT)
PRINT, hash
; Use array syntax to retrieve the "substructure" hash.
PRINT, hash['FIELD2']
; Use special array syntax to access a key within the "substructure".
PRINT, 'SUBFIELD1 = ', hash['FIELD2', 'SUBFIELD1']
IDL prints:
FIELD1: 4.00000
FIELD2: ORDEREDHASH <ID=4 NELEMENTS=2>
SUBFIELD1: hello
SUBFIELD2: 3.14000
SUBFIELD1 = hello
For details on the input arguments and keywords see HASH.
Result = ORDEREDHASH( Key1, Value1, Key2, Value2, ... Keyn, Valuen , /EXTRACT, /FOLD_CASE, /NO_COPY )
or
Result = ORDEREDHASH( Keys, Values, /EXTRACT, /FOLD_CASE )
or
Result = ORDEREDHASH( Keys, /FOLD_CASE)
or
Result = ORDEREDHASH( Structure, /EXTRACT, /FOLD_CASE, /LOWERCASE)
See Hash::Count for detailed documentation.
Result = orderedhash.Count( [Value] )
See Hash::Filter for detailed documentation.
Result = orderedhash.Filter(Function, Args)
See Hash::HasKey for detailed documentation.
Result = orderedhash.HasKey( Keys )
See Hash::IsEmpty for detailed documentation.
Result = orderedhash.IsEmpty( )
See Hash::Keys for detailed documentation.
Result = orderedhash.Keys( )
See Hash::Map for detailed documentation.
Result = orderedhash.Map(Function, Args)
See Hash::Reduce for detailed documentation.
Result = orderedhash.Reduce(Function, Args, /CUMULATIVE, VALUE=value)
If this keyword is set, then the Result will be a hash containing all of the intermediate cumulative results instead of just the final result.
See Hash::Remove for detailed documentation.
ordered hash.Remove [, Keys] [, /ALL]
or
Result = orderedhash.Remove( [, Keys] [, /ALL] )
See Hash::ToStruct for detailed documentation.
Result = orderedhash.ToStruct( [, MISSING=value] [, /NO_COPY] [, /RECURSIVE] [, SKIPPED=variable] )
See Hash::Values for detailed documentation.
Result = orderedhash.Values( )
See Hash::Where for detailed documentation.
Result = orderedhash.Where( Value [, COMPLEMENT=variable] [, COUNT=variable] [, NCOMPLEMENT=variable] )\
See the following sections in HASH for additional information on using ordered hashes:
Just like HASH, you can use the FOREACH operator to iterate over the ordered hash.
Note: While iterating through an ordered hash you should avoid adding or removing elements. If the ordered hash is changed during the FOREACH, the behavior is undefined.
|
8.3 |
Introduced |
|
8.4 |
Added Filter, Map, Reduce methods Added FOLD_CASE keyword |
!NULL, DICTIONARY, HASH, LIST, Logical Operators, Relational Operators, LAMBDA